package list;


import java.util.ArrayList;

public class ListUtil {
    /**
     * 将数组转化成链表的结构
     *
     * @param nums
     * @return
     */
    public static ListNode getListFromArray(int[] nums) {
        ListNode listNode = new ListNode();
        ListNode res = listNode;
        for (int num : nums) {
            listNode.next = new ListNode(num);
            listNode = listNode.next;
        }
        return res.next;
    }

    /**
     * 遍历链表结构
     */
    public static void listToString(ListNode list) {
        ArrayList arr = new ArrayList();
//        if (list == null) {
//            System.out.println("[]");
//        }
        while (list != null) {
//            System.out.println(list.val);
            arr.add(list.val);
            list = list.next;
        }
        System.out.println(arr.toString());

    }
}
